/*
 * driver_map.c
 *
 *  Created on: 2024年4月12日
 *      Author: NI
 */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "driver_map.h"
#include "driver_data.h"
//#include "libdecoder_tp2855.h"

tp2855_dev_t cam_dev = {
		.path = "/dev/i2c1",
		.decoder_addr = 0x44,
		.mipi_config = MIPI_4CH2LANE_594M,
		.camera = {
				.channel = CH_1,
				.fmt = PAL,
				.std = PAL,
				.vchannel = CH_1
		}
};

#include <string.h>
void recv_cam_dev(){
	printf("\n cam_dev.camera.channel = ");
	fflush(stdout);
	scanf("%d", (int *)&cam_dev.camera.channel);
	getchar();
	printf("\n cam_dev.camera.fmt = ");
	fflush(stdout);
	scanf("%d", (int *)&cam_dev.camera.fmt);
	getchar();
	printf("\n cam_dev.camera.std = ");
	fflush(stdout);
	scanf("%d", (int *)&cam_dev.camera.std);
	getchar();
	printf("\n cam_dev.camera.vchannel = ");
	fflush(stdout);
	scanf("%d", (int *)&cam_dev.camera.vchannel);
	getchar();
}

void func_0(){
	char choice = 0;
	while(choice != 'q'){
		printf("\nThis is config for cam_dev:\n");
		printf_cam_dev();
		while(1){
			printf("\nPress 's' to config cam_dev, and 'q' to quit : ");
			fflush(stdout);
			choice = getchar();
			getchar();
			if(choice == 's' || choice == 'q'){
				if(choice == 'q') break;
				recv_cam_dev();
				break;
			}else{
				printf("\nError input!");
			}
		}
	}
}

void func_1(){
	int ret = EOK;
	ret = camera_decoder_init(&cam_dev);
	printf("\ncamera_decoder_init() return [%d]\n", ret);
	fflush(stdout);
}

void func_2(){
	int ret = EOK;
	uint8_t status = 0;
	ret = camera_decoder_check_connect(&cam_dev, &status);
	printf("\ncamera_decoder_check_connect() return [%d] and status is [0x%X]\n", ret, status);
	fflush(stdout);
}

void func_3(){
	int ret = EOK;
	ret = camera_decoder_deinit();
	printf("\ncamera_decoder_deinit() return [%d]\n", ret);
	fflush(stdout);
}

void func_4(){
	int ret = EOK;
	ret = camera_decoder_dump();
	printf("\ncamera_decoder_dump() return [%d]\n", ret);
	fflush(stdout);
}

void func_5(){
	int ret = EOK;
	ret = camera_decoder_init_reg_map(&cam_dev);
	printf("\ncamera_decoder_init_reg_map() return [%d]\n", ret);
	fflush(stdout);
}

void func_6(){
	int ret = EOK;
	ret = camera_decoder_mipi_config(&cam_dev);
	printf("\ncamera_decoder_mipi_config() return [%d]\n", ret);
	fflush(stdout);
}

void func_7(){
	int ret = EOK;
	ret = camera_decoder_mipi_output(1);
	printf("\ncamera_decoder_mipi_output() return [%d]\n", ret);
	fflush(stdout);
}

void func_8(){
	int ret = EOK;
	uint8_t status = 0;
	ret = camera_decoder_check_lock(&cam_dev, &status);
	printf("\ncamera_decoder_check_lock() return [%d] and status is [%d]\n", ret, status);
	fflush(stdout);
}

driver_map_t driver_map[] = {
		{func_0, "0. Config cam_dev\n"},
		{func_1, "1. camera_decoder_init()\n"},
		{func_2, "2. camera_decoder_check_connect()\n"},
		{func_3, "3. camera_decoder_deinit()\n"},
		{func_4, "4. camera_decoder_dump()\n"},
		{func_5, "5. camera_decoder_init_reg_map()\n"},
		{func_6, "6. camera_decoder_mipi_config()\n"},
		{func_7, "7. camera_decoder_mipi_output()\n"},
		{func_8, "8. camera_decoder_check_lock()\n"},
};

void printf_cam_dev(){
	printf("====================\n");
	printf("tp2855_dev_t cam_dev = {	\n");
	printf("	.path = %s,	\n", cam_dev.path);
	printf("	.decoder_addr = 0x%X,	\n", cam_dev.decoder_addr);
	printf("	.mipi_config = %s,	[%d]\n", mipi_config_to_str[cam_dev.mipi_config], cam_dev.mipi_config);
	printf("	.camera = {	\n");
	printf("		.channel = %d,	\n", cam_dev.camera.channel);
	printf("		.fmt = %s,	[%d]\n", fmt_to_str[cam_dev.camera.fmt], cam_dev.camera.fmt);
	printf("		.std = %s,	[%d]\n", std_to_str[cam_dev.camera.std], cam_dev.camera.std);
	printf("		.vchannel = %d,	\n", cam_dev.camera.vchannel);
	printf("}\n====================\n");
}

void printf_msg(){
	int i = 0;
	printf("\nDEBUG List::\n");
	for(i = 0; i < sizeof(driver_map)/sizeof(driver_map_t); i++){
		printf("%s", driver_map[i].msg);
	}
	printf("%d. exit\n", sizeof(driver_map)/sizeof(driver_map_t));
	printf("\nChoice: ");
	fflush(stdout);
}

driver_map_t * get_driver_map(int * size){
	*size = sizeof(driver_map)/sizeof(driver_map_t);
	return driver_map;
}

